import { getToken, setToken, removeToken } from '@/utils/auth'

const user = {
  state: {
    user: '',
    status: '',
    code: '',
    token: getToken(),
    name: '',
    avatar: '',
    introduction: '',
    roles: [],
    setting: {
      articlePlatform: []
    }
  },

  mutations: {
    SET_CODE: (state, code) => {
      state.code = code
    },
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_INTRODUCTION: (state, introduction) => {
      state.introduction = introduction
    },
    SET_SETTING: (state, setting) => {
      state.setting = setting
    },
    SET_STATUS: (state, status) => {
      state.status = status
    },
    SET_NAME: (state, name) => {
      state.name = name
    },
    SET_AVATAR: (state, avatar) => {
      state.avatar = avatar
    },
    SET_ROLES: (state, roles) => {
      state.roles = roles
    }
  },

  actions:{
     // 获取用户信息
     GetUserInfo({ commit, state }) {
      return new Promise((resolve, reject) => {
          commit('SET_ROLES', 'admin')
          commit('SET_NAME', 'jack')
          commit('SET_AVATAR', 'http://element-cn.eleme.io/static/hamburger.50e4091.png')
          commit('SET_INTRODUCTION', '开学')
          resolve(['admin'])
        }).catch(error => {
          reject(error)
        })
    },
    //退出登录
    Logout({commit}){
      removeToken()
    }
  }
}



export default user
